<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="travelCommend"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <select name="type" class="form-control">
                    <option value="-1">全部</option>
                    <option value="1">每周推荐</option>
                    <option value="2">每月推荐</option>
                    <option value="3">攻略推荐</option>
                </select>
                <a role="button" class="btn btn-success searchBtn">
                    <span class="glyphicon glyphicon-search"></span>查询
                </a>
            </form>
            <script>
                $("select[name='type']").val(${qo.type});
            </script>
            <table class="table table-striped table-hover" >
                <thead>
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间</th>
                    <th>推荐类型</th>
                    <th></th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td><img src="${entity.coverUrl}" style="width: 30px"></td>
                       <td>${entity.title}</td>
                       <td>${entity.subTitle}</td>
                       <td>
                           ${entity.schedule?string("yyyy-MM-dd")}
                       </td>
                       <td>${entity.typeName!}</td>
                        <td>
                            <a role="button" class="btn btn-xs btn-danger updateBtn"
                            data-json='${entity.json!}'>
                                <span class="glyphicon glyphicon-pencil"></span>修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<#--新增游记推荐模态框-->
<div class="modal fade" id="commendModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="commendForm" enctype="multipart/form-data">
                    <input type="hidden" name="id" />
                    <input type="hidden" name="coverUrl"/>
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="img">
                            <input type="file" class="form-control" name="file"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a  class="showTravel" target="_blank" >点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary commendSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".searchBtn").click(function () {
            $("#searchForm").submit();
        });
        $(".updateBtn").click(function () {
            var json = $(this).data("json");
            $("#commendForm input").val("");
            if (json) {
                $("#commendForm input[name='id']").val(json.id);
                $("#commendForm input[name='title']").val(json.title);
                $("#commendForm input[name='subTitle']").val(json.subTitle);
                $("#commendForm input[name='coverUrl']").val(json.coverUrl);
                $("#commendForm input[name='schedule']").val(json.schedule);
                $("#commendForm select[name='type']").val(json.type);
                $(".showTravel").attr("href",'/travel/releaseList.do?travelId='+json.travelId);

                $("#img").attr("src",json.coverUrl);
            }
            $("#commendModal").modal("show");
        });
        $("#file").change(function () {
            if($(this).val()){
                $("#commendForm input[name='coverUrl']").val($(this).val());
            };
        });
        $("#commendForm").ajaxForm(function (data) {
            if (data.success) {
                reload();
            }
        });
        $(".commendSubmitBtn").click(function () {
            $("#commendForm").submit();
        });
    });
</script>
<style>
    #commendModal img{
        width: 100%;
    }
</style>
</body>
</html>